<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
    $fields=array('id','title','path','type');
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('core_account_wxapp_jump',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'跳转小程序列表'),
			array('op'=>'edit','title'=>'添加跳转小程序'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'title','title'=>'小程序名称','type'=>'string'),
			array('name'=>'path','title'=>'路径','type'=>'string'),								
			array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'type'),
		),
		),
		'search'=>array(
			array('name'=>'title','width'=>'15','title'=>'名称','type'=>'string'),
			
		)
	);
	$return['type']=array(
	'1'=>'DIY小程序',
	'2'=>'插件小程序',
	'7'=>'打包小程序',
	'8'=>'多页小程序',
	);
	$return['htmls']=$htmls;
	exi($return);
	}
	if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
	$item=pdo_get('core_account_wxapp_jump',array('id'=>$id));
	}else{
		$item=array();
	}
    $return['item']=$item;
	
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'跳转小程序设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'跳转小程序列表'),
			array('op'=>'edit','title'=>'添加跳转小程序')
		),
		'edit'=>array(
			array('name'=>'wxid','title'=>'选择小程序','type'=>'select','options'=>'wxapp'),			
			array('name'=>'path','title'=>'跳转路径','type'=>'string','help'=>'打开的页面路径，如果为空则打开首页。格式：/pages/index/index'),
			)
			);
	$return['wxapp']=pdo_getall('core_account_wxapp',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['htmls']=$htmls;
	exi($return);
	}
	if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array_fields(array('wxid'),$postdata);
	$app=pdo_get('core_account_wxapp',array('id'=>$postdata['wxid']));
	$data['title']=$app['title'];
	$data['type']=$app['type'];
	$data['appid']=$app['appid'];
	if(!$postdata['path']){
		$data['path']=$app['url'];
	}else{
		$data['path']=$postdata['path'];
	}
	$id=intval($postdata['id']);
			if($id){
				pdo_update('core_account_wxapp_jump',$data,array('id'=>$id));
				exi('设置成功！','','list');
			}else{
			    $data['uniacid']=$_SESSION['uniacid'];
				pdo_insert('core_account_wxapp_jump',$data);
				exi('添加成功！','','list');
			}
			}
	if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('core_account_wxapp_jump',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('core_account_wxapp_jump',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>